home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
blankery
/
blanker
/
source
/
blankers
/
life
/
blank.c
next >
Wrap
C/C++ Source or Header
|
1993-08-15
|
4KB
|
144 lines
/*
* Copyright (c) 1993 Michael D. Bayne.
* All rights reserved.
*
* Please see the documentation accompanying the distribution for distribution and disclaimer information.
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <graphics/rastport.h>
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/alib_protos.h>
#include "Life.h"
#include "/utility.h"
struct lPrefObject {
LONG Size;
LONG Generations;
LONG Density;
};
extern struct lPrefObject nP;
extern ULONG Mode, Depth;
extern UBYTE *prefData;
VOID blank( VOID )
{
struct lPrefObject *lP;
struct Screen *LScr;
struct RastPort *r;
LONG iter = 0, colrand = (1L<<Depth)-1, xpos, ypos, n = 0, m = 1, Density, Size, Gens;
WORD w, h, i, gi, li, j, gj, lj, BWid;
BYTE **Org[2], nbrs;
if( LifeWnd ) lP = &nP;
else lP = ( struct lPrefObject * )prefData;
Density = lP->Density;
Size = lP->Size;
Gens = lP->Generations;
BWid = Size - 2;
if( LScr = OpenScreenTags( 0l, SA_DisplayID, Mode, SA_Depth, Depth, SA_Quiet, TRUE, SA_Behind, TRUE,
SA_Overscan, OSCAN_TEXT, TAG_DONE )) {
r = &( LScr->RastPort );
w = LScr->Width / Size;
h = LScr->Height / Size;
if(( Org[n] = AllocVec( sizeof( BYTE * ) * w, MEMF_CLEAR ))&&
( Org[m] = AllocVec( sizeof( BYTE * ) * w, MEMF_CLEAR ))) {
for( i = 0; i < w; i++ ) {
if(!( Org[n][i] = AllocVec( h, MEMF_CLEAR ))) break;
if(!( Org[m][i] = AllocVec( h, MEMF_CLEAR ))) break;
}
if( i == w ) {
SetRGB4( &( LScr->ViewPort ), 0, 0, 0, 0 );
for( i = 1; i < (1L<<Depth)-1; i++ ) SetRGB4( &( LScr->ViewPort ), i,
RangeRand( 0x0A )+5, RangeRand( 0x0A )+5, RangeRand( 0x0A )+5 );
BlankMousePointer();
ScreenToFront( LScr );
while(!( SetSignal( 0L, 0L ) & SIGBREAKF_CTRL_C )) {
WaitTOF();
if( !iter ) {
SetRast( r, 0 );
for( xpos = 0, i = 0; i < w; i++, xpos += Size ) {
for( ypos = 0, j = 0; j < h; j++, ypos += Size ) {
if( RangeRand( 100 ) < Density ) {
Org[n][i][j] = 1;
SetAPen( r, RangeRand( colrand )+1 );
RectFill( r, xpos, ypos, xpos + BWid, ypos + BWid );
} else Org[n][i][j] = 0;
Org[m][i][j] = 0;
}
}
}
for( xpos = 0, i = 0; i < w; i++, xpos += Size ) {
for( ypos = 0, j = 0; j < h; j++, ypos += Size ) {
gi = ( i + 1 )%w;
if( i ) li = ( i - 1 )%w;
else li = w-1;
gj = ( j + 1 )%h;
if( j ) lj = ( j - 1 )%h;
else lj = h-1;
nbrs = Org[n][gi][gj];
nbrs += Org[n][i ][gj];
nbrs += Org[n][li][gj];
nbrs += Org[n][gi][j ];
nbrs += Org[n][li][j ];
nbrs += Org[n][gi][lj];
nbrs += Org[n][i ][lj];
nbrs += Org[n][li][lj];
switch( nbrs ) {
case 3:
Org[m][i][j] = 1;
if( Org[n][i][j] == 0 ) {
SetAPen( r, RangeRand( colrand )+1 );
RectFill( r, xpos, ypos, xpos + BWid, ypos + BWid );
}
break;
case 2:
Org[m][i][j] = Org[n][i][j];
break;
default:
Org[m][i][j] = 0;
if( Org[n][i][j] ) {
SetAPen( r, 0 );
RectFill( r, xpos, ypos, xpos + BWid, ypos + BWid );
}
}
}
}
n = m;
m = 1 - m;
iter = (iter+1) % Gens;
}
SetSignal( 0L, SIGBREAKF_CTRL_C );
}}
if( Org[0] ) {
for( i = 0; i < w; i++ ) if( Org[0][i] ) FreeVec( Org[0][i] );
FreeVec( Org[0] );
}
if( Org[1] ) {
for( i = 0; i < w; i++ ) if( Org[1][i] ) FreeVec( Org[1][i] );
FreeVec( Org[1] );
}
UnblankMousePointer();
CloseScreen( LScr );
}
}